package com.lc.user.express.httpserver;

import android.text.TextUtils;

import com.lc.user.express.model.AddrModel;
import com.lc.user.express.utils.PublicMethod;
import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.http.note.HttpInlet;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/4/14.订单详情
 */
@HttpInlet(Net.GET_ORDER_INFO)
public class GetOrderInfo extends ZJDBAsyGet<GetOrderInfo.Info> {
    public String orderid,userid;

    public GetOrderInfo(String orderid,String userid, AsyCallBack listener) {
        super(listener);
        this.orderid = orderid;
        this.userid = userid;
    }

    @Override
    protected Info parser(JSONObject object) {
        if (object.optInt("message") == 1) {
            Info info = new Info();
            info.avatar = Net.SERVER + object.optString("avatar");
            info.name = object.optString("name");
            info.license = object.optString("license");
            info.posttime = object.optString("posttime");
            info.cartype = object.optString("cartype");
            info.account = object.optString("account");
            info.checkinfo = object.optInt("checkinfo");
            info.isbackorder = object.optInt("isbackorder");
            info.isbackmoney = object.optInt("isbackmoney");
            info.ismove = object.optInt("ismove");
            info.backmoney = object.optString("backmoney");
            info.cid = object.optString("cid");
            JSONArray jsonArray = object.optJSONArray("addresslist");
            for(int i=0;i<jsonArray.length();i++){
                JSONObject jsonObject = jsonArray.optJSONObject(i);
                AddrModel model = new AddrModel();
                model.setAddr(jsonObject.optString("address"));
                model.setName(jsonObject.optString("name"));
                model.setPoint(jsonObject.optString("point"));
                model.setMobile(jsonObject.optString("mobile"));
                if(!TextUtils.isEmpty(jsonObject.optString("point"))){
                    String[] s = jsonObject.optString("point").split(",");
                    model.setLng(PublicMethod.strToDouble(s[1]));
                    model.setLat(PublicMethod.strToDouble(s[0]));
                }
                info.addresslist.add(model);
            }
            return info;
        } else {

        }
        return null;
    }

    public static class Info {
        public String avatar,name,license,posttime,cartype,account,backmoney,cid;
        public int checkinfo,isbackorder,isbackmoney,ismove;
        public List<AddrModel> addresslist = new ArrayList<>();
    }
}
